package com.wz.test;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MyInvocationHandler implements InvocationHandler {
	
	
	//被代理对象 
	private Object target;
	
	MyInvocationHandler(Object target){
		this.target = target;
	}
	
	
	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		
		
		System.out.println("start....");
		
		Object result =  method.invoke(target, args);
		
		System.out.println("end....");
		
		return result;
		
	}
	
	//生成代理对象
	
	public Object getProxy(){
		ClassLoader loader = Thread.currentThread().getContextClassLoader();
		Class<?>[] interfaces = target.getClass().getInterfaces();
		return Proxy.newProxyInstance(loader, interfaces, this);	
	}
}
